package com.lenovo.leos.filebrowser.ui;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.lenovo.leos.filebrowser.netdisk.NetFile;

import android.content.Context;
import android.util.Log;

public class Constant {
	private static final String TAG = "Constant";
	
	public final static int CALL_FILEMAN = 0;
	public final static int CALL_EDIT = 1;
	public final static int CALL_SEARCH = 2;
	
	//menu operations
	public final static int _ATTRIDISPLAY = 0;
	public final static int _COPY = 1;
	public final static int _CUT = 2;
	public final static int _DELETE = 3;
	public final static int _RENAME = 4;
	public final static int _COMPRESS = 5;
	public final static int _DECOMPRESS = 6;
	public final static int _SEARCH = 7;
	public final static int _CREATEDIR = 8;
	public final static int _CREATEFILE = 9;
	public final static int _DONE = 10;
	
	//activity State
	/*
	public final static int _LIST = 11;
	public final static int _EDIT = 12;
	public final static int _OPEAETION = 13;
	*/
	public final static int _LIST = 10;
	
	// source from
	public final static int FROM_PATH = 13;
	public final static int FROM_CLIP = 14;
	
	// for edit activity
	public final static int FROM_BROWSER = 0;
	public final static int FROM_SEARCH = 1;
	
	// sort method
	public final static int SORT_BY_NAME = 0;
	public final static int SORT_BY_TYPE = 1;
	public final static int SORT_BY_TIME = 2;
	public final static int SORT_BY_SIZE = 3;
	
	// thumbnail width and height;
	public final static int THUMBNAIL_WIDTH = 60;
	public final static int THUMBNAIL_HEIGHT = 60;
	
	// constant
	public final static int FILE_NAME_NUM_MAX = 85;
	public final static int LOC_STRING_LENGTH_MAX = 30;
	public final static String ZIPENDSTRING = ".zip";
	
	public static final String LOC_ROOT_DATA_ES = "es";
	
	//simulation disk
	public final static String root = "/";
//	public final static String localroot = "/sdcard/";

//	public final static String uroot = "/udisk/";
	public final static String invalidDir="LOST.DIR";
	
	// system folder
//	public final static String SYSDIR[] = {"camera", "document", 
	// "download","lenovodata", "music", "video", "photo", "record", "library"};
//	Photos Videos Records Musics Documents Others
		
    // root 
	public static final String LOCAL_STORAGE_PATH = "/data";
	//public final static String sdroot = "/sdcard";
//	public final static String sdroot = "/sdcard";
	public final static String sdroot = "/mnt/sdcard";///sdcard/extra_sd
//	public final static String sdroot = LOCAL_STORAGE_PATH;
	public static final File [] realRoots = {new File(sdroot), new File("/sdcard")};
	
	public static final File GPS_MAP_DIR = new File(sdroot + "/gpsmap");
	public static final File SYSDIR_ROOT = new File(sdroot + "/LeZone Library");	
//	public final static String SYSDIR[] = {"Music", "Videos", "Photos", "E-Books", 	
//		"Documents", "Recent"};
	public final static String SYSDIR[] = {"camera", "document", "download", "music", "video"};
	
//	public static final File[] SYS_FOLDERS = {new File("/sdcard/camera"), new File("/sdcard/document"),
//		new File("/sdcard/music"), new File("/sdcard/video")};
	public static final File[] SYS_FOLDERS = {new File(sdroot + "/camera"), new File(sdroot + "/document"),
		new File(sdroot + "/music"), new File(sdroot + "/video")};
// Music Videos Photos E-Books Documents Recent

	public static String SYSDIR_CN[] = null;
	
	public static final String MIMETYPE_CATEGORY_FOR_DIR = "dir";
	public static final String MIMETYPE_FOR_COM_DIR = MIMETYPE_CATEGORY_FOR_DIR + "/com";
	public static final String MIMETYPE_FOR_SYS_DIR = MIMETYPE_CATEGORY_FOR_DIR + "/sys";
	
	public static String textConvert(Context context, String name){
	/*	if(SYSDIR_CN == null)
		   SYSDIR_CN = context.getResources().getStringArray(R.array.sys_dir_cn);
		
		if(SYSDIR_CN == null)
			return name;
		//"/Camera", "/Document", "/Music", "/Picture", "/Record", "/Video"
    	if(Locale.getDefault().equals(Locale.SIMPLIFIED_CHINESE) || 
    				Locale.getDefault().equals(Locale.CHINA) || 
    				Locale.getDefault().equals(Locale.CHINESE)){
    		if(name.equals(SYSDIR[0]))
    			return SYSDIR_CN[0];
    		else if(name.equals(SYSDIR[1]))
    			return SYSDIR_CN[1];
    		else if(name.equals(SYSDIR[2]))
    			return SYSDIR_CN[2];
    		else if(name.equals(SYSDIR[3]))
    			return SYSDIR_CN[3];
    		else if(name.equals(SYSDIR[4]))
    			return SYSDIR_CN[4];
    		else if(name.equals(SYSDIR[5]))
    			return SYSDIR_CN[5];
    	}
    	*/
    	return name;
    }
	
	public static boolean isRealRoot(File file){
		for (File f : realRoots)
			if (file.equals(f))
				return true;
		return false;
/*		if (!file.equals(realRoots[0]) && !file.equals(realRoots[1])) 
			return false;
		else
			return true;*/
	}
	
	public static boolean isSysFile(final File file) {
		if(null == file || !file.exists()){
			Log.e(TAG, "file is invalid in isSysFile");
			return false;
		}else{
//			if(file.getAbsolutePath().startsWith(SYSDIR_ROOT.getAbsolutePath()))
			boolean res = false;
			for (File f : SYS_FOLDERS){
				if (f.getAbsolutePath().equals(file.getAbsolutePath())){
					res = true;
					break;
				}
			}
				return res;
		}
	}
	
	public static boolean isSysOrReservedDir(Context context, File file){
		//if(SYSDIR_CN == null)
		//	   SYSDIR_CN = context.getResources().getStringArray(R.array.sys_dir_cn);
		String sDirPath = file.getAbsolutePath();
//		Log.d(TAG, "********* isSysOrReservedDir: " + sDirPath);
		if (sDirPath.equals(Constant.sdroot + "/" + SYSDIR[0]))
			return true;
		if (sDirPath.equals(Constant.sdroot + "/" + SYSDIR[1]))
			return true;
		if (sDirPath.equals(Constant.sdroot + "/" + SYSDIR[2]))
			return true;
		if (sDirPath.equals(Constant.sdroot + "/" + SYSDIR[3]))
			return true;
		if (sDirPath.equals(Constant.sdroot + "/" + SYSDIR[4]))
			return true;
//	    if(sDirPath.equals(Constant.sdroot + "/" + SYSDIR[5]))
//	    	 return true;
	    /*if(SYSDIR_CN != null){
		    if(sDirName.equals(Constant.sdroot+SYSDIR_CN[0]))
		    	 return true;
		    if(sDirName.equals(Constant.sdroot+SYSDIR_CN[1]))
		    	 return true;
		    if(sDirName.equals(Constant.sdroot+SYSDIR_CN[2]))
			    return true;
		    if(sDirName.equals(Constant.sdroot+SYSDIR_CN[3]))
				 return true;
		    if(sDirName.equals(Constant.sdroot+SYSDIR_CN[4]))
		    	 return true;
		    if(sDirName.equals(Constant.sdroot+SYSDIR_CN[5]))
		    	 return true;
	    }*/
	
	return false;
}
	
	
/*	public static List<File> getSysDir(){
    	List<File> sysList = new ArrayList<File>();
    	sysList.clear();
    	String [] sysdir = Constant.SYSDIR;
    	for(int i=0;i<sysdir.length;i++){
    		String sysDirPath = Constant.sdroot + sysdir[i];
    		sysList.add(new File(sysDirPath));
    	}  	
    	return sysList;  	
    }*/
	
	public static List<File> getSysDir(Context context, List<File> file){
		List<File> sysList = new ArrayList<File>();
		Log.i(TAG, "***********************path = "+file.get(0).getParent() + "/");
			for(int i=0;i<file.size();i++)
				if(Constant.isSysOrReservedDir(context, file.get(i)))
					sysList.add(file.get(i));
		Log.i(TAG, "sysList========="+sysList.size());
		return sysList;
	}
	///////////
	
	public static boolean isForUser(File file) {
		if (null == file || !file.exists())
			return false;
		else {
			// [improve] check whether it is in real root.
			return true;
		}
	}	
}
